#include "menu.h"

int Random(int min , int max)
{
    return (rand()% (max-min))+min;

}


void initialiser()
{
    allegro_init();
    install_keyboard();
    set_color_depth(32); //palette de couleur 32
    set_gfx_mode(GFX_AUTODETECT_WINDOWED,800,593,0,0);

}



void chargerMenu(Menu *monMenu)
{
    monMenu->images[0]=load_bitmap("menu_PLAY.bmp",NULL);
    monMenu->images[1]=load_bitmap("menu_helpcurs.bmp",NULL);
    monMenu->images[2]=load_bitmap("menu_EXIT.bmp",NULL);
    int i;
    for(i=0;i<NB_IMAGES_MENU;i++)
    {
        if (monMenu->images[i] == NULL)
        {
            allegro_message("could not load images");
            allegro_exit();
        }
    }


    monMenu->elementSelectioner=0;
}



void menu(Menu *monMenu, int *choix)
{
    int state=0;

    while(!state)
    {
        static int touchePresse;
        if(keypressed())
        {
            touchePresse=readkey();
            if ((touchePresse>>8) == KEY_DOWN)
            {
                monMenu->elementSelectioner=(monMenu->elementSelectioner+1)%3;
            }
            else if(touchePresse>>8 == KEY_UP)
            {
                if(monMenu->elementSelectioner==0) monMenu->elementSelectioner=2;
                else
                    monMenu->elementSelectioner=(monMenu->elementSelectioner-1)%3;
            }
            else if(touchePresse>>8 == KEY_ENTER)
                state=1;
        }

        draw_sprite(screen, monMenu->images[monMenu->elementSelectioner], 0, 0);

    }
    *choix=monMenu->elementSelectioner;

}





